<template>
	<view class="container">
		<u-navbar :title="title" :autoBack="false" :bgColor="bgColor" :titleStyle="titleStyle" titleWidth="300rpx"
			:fixed="fixed" @leftClick="$emit('leftClick')">
			<view class="u-nav-slot" slot="left">
				<view class="navbar-left u-flex-center" v-if="toBack">
					<u-icon name="arrow-left" size="23" @click="toBackChange(1)" :color="color"></u-icon>
					<u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
					<u-icon name="home" size="25" @click="toBackChange(2)" :color="color"></u-icon>
				</view>
			</view>
		</u-navbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		props: {
			title: {
				type: String,
				default: ''
			},
			toBack: {
				type: Boolean,
				default: true
			},
			bgColor: {
				type: String,
				default: '#FFFFFF'
			},
			color: {
				type: String,
				default: '#000000'
			},
			titleStyle: {
				type: Object,
				default: {}
			},
			fixed: {
				type: Boolean,
				default: true
			}
		},
		methods: {
			toBackChange(type = 1) {
				if (type == 1) {
					let pages = getCurrentPages();
					var beforePage = pages[pages.length - 2]; // 获取上一个页面实例对象
					// 没有上一页 || 上一页是否是验证码登录页
					if (beforePage === undefined) {
						this.$switchTab('/pages/index/index');
					} else {
						this.$toBack();
					}
				} else {
					this.$switchTab('/pages/index/index')
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.navbar-left {
		padding: 5rpx 15rpx;
		box-sizing: border-box;
		border: 2rpx solid #EFEFF0;
		border-radius: 50rpx;
	}
</style>